package lc.com.lcpicturebackend.controller;

import cn.hutool.core.util.ObjectUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lc.com.lcpicturebackend.common.BaseResponse;
import lc.com.lcpicturebackend.common.ResultUtils;
import lc.com.lcpicturebackend.exception.ErrorCode;
import lc.com.lcpicturebackend.exception.ThrowUtils;
import lc.com.lcpicturebackend.model.dto.chatai.ConversationMsgQueryRequest;
import lc.com.lcpicturebackend.model.entity.User;
import lc.com.lcpicturebackend.model.vo.chat.ConversationMsgVO;
import lc.com.lcpicturebackend.service.ConversationMsgService;
import lc.com.lcpicturebackend.service.UserService;
import org.springframework.web.bind.annotation.*;


/**
 * 会话控制器
 */
@RestController
@CrossOrigin
@RequestMapping("/chatmsg")
public class ConversationMsgController {

    @Resource
    private ConversationMsgService conversationMsgService;

    @Resource
    private UserService userService;


    /**
     * 获取聊天会话列表
     *
     * @param conversationQueryRequest 会话id
     * @return 会话
     */
    @PostMapping("/getConversationBypage")
    public BaseResponse<ConversationMsgVO> getConversationMsgListVO(@RequestBody ConversationMsgQueryRequest conversationQueryRequest,
                                                                 HttpServletRequest request) {
        ThrowUtils.throwIf(ObjectUtil.isEmpty(conversationQueryRequest), ErrorCode.PARAMS_ERROR);
        User loginUser = userService.getLoginUser(request);

        return ResultUtils.success(conversationMsgService.getConversationMsgListVO(conversationQueryRequest, loginUser));
    }

}



